<template>
  <van-form @submit="onSubmit">
    <div class="new-login">
      <img class="bg-class" src="@/assets/image/bg_landingbackground.png">
      <div class="login-head">
        <div class="login-icon"
             :style="{background: 'url('+require('@/assets/image/juyuan_park.png')+')',backgroundRepeat: 'no-repeat',backgroundSize: 'cover'}">
        </div>
      </div>
      <div class="login-cont">
        <div class="login-form">
          <div class="form agent-form">
            <div class="login-item">
              <van-field v-model="fromData.username" label-width="40" label="账号" maxlength="16"
                         onkeyup="this.value=this.value.replace(/[/W]/g,'')" placeholder="请输入您的代理商账号"/>
            </div>

            <div class="login-item">
              <van-field v-model="fromData.password" label-width="40" label="密码" maxlength="16" type="password"
                         onkeyup="this.value=this.value.replace(/[/W]/g,'')" placeholder="请输入您的密码"/>
            </div>
          </div>
        </div>
        <div class="login-item no-border">
          <div class="button-layout">
            <van-button round type="info">登录</van-button>
          </div>
          <p class="login-reset">
            <span style="color: #99FFFFFF">如忘记密码请联系管理员重置</span>
          </p>
        </div>
      </div>
    </div>
  </van-form>
</template>

<script>
  import {login} from "@/api/login";
  import {getToken, setToken} from '@/utils/auth'

  export default {
    name: "login",
    data() {
      return {
        fromData: {
          username: '',
          password: ''
        }
      }
    },
    mounted() {
      this.init();
    },
    methods: {
      init() {
        let token = getToken();
        if (token != null && token != '') {
          this.$router.push({path: '/home'})
        }
      },
      onSubmit() {
        login(this.fromData).then(response => {
          setToken(response.data);
          this.$router.push({path: '/home'})
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import './index.scss';
</style>
